package cn.neusoft.controller;

import cn.neusoft.pojo.Order;
import cn.neusoft.query.OrderQuery;
import cn.neusoft.service.IOrderService;
import cn.neusoft.vo.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class OrderController {
	@Autowired
	private IOrderService orderService;
	@PostMapping      //  请求方式 + 请求路径   post  /order
	public ResultBean add(@RequestBody Order order) throws Exception {
		System.out.println("----OrderController-----add--------");
		System.out.println(order);
		return  orderService.add(order);
	}
	@PutMapping
	public ResultBean upddate(@RequestBody Order order) throws Exception {
		System.out.println("----OrderController-----update--------");
		return orderService.update(order);
	}
	@DeleteMapping("/{id}")
	public ResultBean delete(@PathVariable("id") Integer id) throws Exception {
		System.out.println("----OrderController-----delete--------");
		return orderService.delete(id);
	}
	@GetMapping("/{id}")
	public ResultBean getById (@PathVariable("id") Integer id) throws Exception {
		System.out.println("----OrderController-----getById--------");
		return orderService.getById(id);
	}
	@GetMapping("/all")
	public ResultBean getAll ( ) throws Exception {
		System.out.println("----OrderController-----getAll--------");
		return orderService.getAll();
	}
	@PostMapping("/page")
	public ResultBean getByPage(@RequestBody OrderQuery orderQuery) throws  Exception {
		System.out.println("----OrderController-----getByPage--------");
		System.out.println(orderQuery);
		return  orderService.getByPage(orderQuery);
	}
	//根据订单编号来查询订单详情
	@GetMapping("/detail/{orderId}")
	public ResultBean getDetailsByOrderId (@PathVariable("orderId") Integer orderId) throws Exception {
		System.out.println("----OrderController-----getDetailsByOrderId--------");
		return orderService.getDetailsByOrderId(orderId);
	}
}
